//
//  NXANonIssueContentView.m
//  NXA-MasterDrivingSkills
//
//  Created by jps on 2017/1/5.
//  Copyright © 2017年 NXA. All rights reserved.
//

#import "NXANonIssueContentView.h"

#define W (CURRENT_SCREEN_WIDTH/8.0)
#define lineW 0.5

@interface NXANonIssueContentView ()



@property(nonatomic,strong)UILabel *timeLabel;
@property(nonatomic,strong)UILabel *carTypeLabel;
@property(nonatomic,strong)UILabel *kemuLabel;
@property(nonatomic,strong)UILabel *moneyLable;
@property(nonatomic,strong)UILabel *personCountLabel;

@property(nonatomic,strong)NSArray *labelArr;






@end

@implementation NXANonIssueContentView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIColor *color = kColor(235, 235, 235);
        [self initComponentsWithLineHeight:1 color:color];
        
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        UIColor *color = kColor(250, 250, 250);
        [self initComponentsWithLineHeight:4 color:color];
    }
    return self;
}

- (void)layoutSubviews
{
    //这个方法在setter之后走，把控件放这里初始化，根本赋不上值
    //[self initComponents];
}


- (void)initComponentsWithLineHeight:(CGFloat)lineH color:(UIColor *)color
{
    self.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.4];
    
    CGFloat height = self.frame.size.height - lineH;
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, W-lineW, height)];
    view.backgroundColor = color;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapToSelectedAll:)];
    [view addGestureRecognizer:tap];
    if (lineH > 2) {
        //如果是cell，禁掉此手势，是头则开启
        view.userInteractionEnabled = NO;
    }
    [self addSubview:view];
    self.selctedButton = [[UIButton alloc]init];
    self.selctedButton.userInteractionEnabled = NO;
    self.selctedButton.center = view.center;
    self.selctedButton.bounds = CGRectMake(0, 0, height/2, height/2);
    self.selctedButton.layer.borderColor = [UIColor lightGrayColor].CGColor;
    [self.selctedButton setImage:[UIImage imageNamed:@"xz"] forState:UIControlStateSelected];
    self.selctedButton.layer.borderWidth = 0.5;
    self.selctedButton.layer.cornerRadius = height/4;
    [view addSubview:self.selctedButton];
    
    
    self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(view.frame.size.width+lineW, 0, W*2.0-lineW, height)];
    self.timeLabel.backgroundColor = color;
    self.timeLabel.userInteractionEnabled = YES;
    self.timeLabel.textAlignment = NSTextAlignmentCenter;
    self.timeLabel.adjustsFontSizeToFitWidth = YES;
    [self addSubview:self.timeLabel];
    
    self.carTypeLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.timeLabel.frame)+lineW, 0, W-lineW, height)];
    self.carTypeLabel.backgroundColor = color;
    self.carTypeLabel.userInteractionEnabled = YES;
    self.carTypeLabel.adjustsFontSizeToFitWidth = YES;
    self.carTypeLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.carTypeLabel];
    
    self.kemuLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.carTypeLabel.frame)+lineW, 0, W*2-lineW, height)];
    self.kemuLabel.backgroundColor = color;
    self.kemuLabel.userInteractionEnabled = YES;
    self.kemuLabel.adjustsFontSizeToFitWidth = YES;
    self.kemuLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.kemuLabel];
    
    self.moneyLable = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.kemuLabel.frame)+lineW, 0, W-lineW, height)];
    self.moneyLable.backgroundColor = color;
    self.moneyLable.userInteractionEnabled = YES;
    self.moneyLable.adjustsFontSizeToFitWidth = YES;
    self.moneyLable.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.moneyLable];
    
    self.personCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.moneyLable.frame)+lineW, 0, W-lineW, height)];
    self.personCountLabel.backgroundColor = color;
    self.personCountLabel.userInteractionEnabled = YES;
    self.personCountLabel.adjustsFontSizeToFitWidth = YES;
    self.personCountLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.personCountLabel];
    self.labelArr = @[self.timeLabel, self.carTypeLabel, self.kemuLabel, self.moneyLable, self.personCountLabel];
}



#pragma mark - EventsHandle

- (void)tapToSelectedAll:(UITapGestureRecognizer *)tap
{
    self.isSelected = !self.isSelected;
    
//    DLog(@"2 %d",self.isSelected);
    //选中所有cell的回调
    if (_selectedAllCallBack) {
        _selectedAllCallBack(self.isSelected);
    }
}


#pragma mark - setter

//cell内容字段值
- (void)setSegmentModel:(NXATimeSegmentModel *)segmentModel
{
    _segmentModel = segmentModel;
    
    self.timeLabel.text = segmentModel.Reservation_HH;
    self.carTypeLabel.text = segmentModel.learn_type;
    self.kemuLabel.text = segmentModel.subject_type;
    self.moneyLable.text = segmentModel.fee;
    self.personCountLabel.text = segmentModel.check_number;
}

//头字段值
- (void)setDataSourceArr:(NSArray *)dataSourceArr
{
    _dataSourceArr = dataSourceArr;
    
    for (int i = 0; i < dataSourceArr.count; i++) {
        UILabel *label = self.labelArr[i];
        label.text = dataSourceArr[i];
    }
}



- (void)setIsSelected:(BOOL)isSelected
{
    _isSelected = isSelected;
    //设置btn选中状态，让图片显示或隐藏
    self.selctedButton.selected = isSelected;
    
}


- (void)setSelectedAllCallBack:(SelectedAllCallBack)selectedAllCallBack
{
    _selectedAllCallBack = selectedAllCallBack;
}



@end
